﻿
namespace DotNetImage.Imaging.Filters
{
    public class InvertFilter : FilterBase
    {
        private uint MaxValue = 0;
        private int ColorChannelCount = 0;

        protected override void PrepareData(DotNetImage bmp)
        {
            base.PrepareData(bmp);
            MaxValue = bmp.ColorChannelMaxValue;
            ColorChannelCount = bmp.ColorChannelCount;
        }
        protected override void ProcessPixel(ref Pixel pix, uint x, uint y)
        {
            pix.Red = MaxValue - pix.Red;
            if (ColorChannelCount >= 3)
            {
                pix.Green = MaxValue - pix.Green;
                pix.Blue = MaxValue - pix.Blue;
                if (ColorChannelCount == 4)
                {
                    pix.Alpha = MaxValue - pix.Alpha;
                }
            }
        }
    }
}
